<template>
  <div>
    <h1>商家页面</h1>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="userId" label="ID" />
      <el-table-column prop="userName" label="名称" />
      <el-table-column prop="userMobile" label="手机号" />
      <el-table-column prop="userEmail" label="邮箱" />
      <el-table-column prop="userGender" label="性别" />
      <el-table-column prop="userAvatar" label="头像" />
      <el-table-column prop="createTime" label="注册时间" />
      <el-table-column prop="address" label="操作" />
    </el-table>
    <div class="demo-pagination-block">
      <el-pagination
        v-model:current-page="form.pageNum"
        v-model:page-size="form.pageSize"
        :page-sizes="[2, 3, 4, 5]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { getUserList } from "../api/api";
import type { ComponentSize } from "element-plus";
const tableData = ref([]);
const total = ref(0);
const size = ref<ComponentSize>("default");
const background = ref(false);
const disabled = ref(false);

const form = ref({
  pageNum: 1,
  pageSize: 2,
});
const getUser = () => {
  getUserList(form.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  form.value.pageSize = val;
  getUser();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  form.value.pageNum = val;
  getUser();
};
onMounted(() => {
  getUser();
});
</script>
